package com.itkaien.service.impl;

import com.github.pagehelper.PageInfo;
import com.itkaien.mapper.InventoryMapper;
import com.itkaien.pojo.Goods;
import com.itkaien.pojo.Inventory;
import com.itkaien.service.GoodsService;
import com.itkaien.service.InventoryService;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class InventoryServiceImpl implements InventoryService {

    @Autowired
    private InventoryMapper inventoryMapper;

    @Override
    public void addinventory(Inventory inventory) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        Date date = Date.from(instant);
        inventory.setCreateTime(date);
        inventoryMapper.insert(inventory);
    }

    @Override
    public void updateinventory(Inventory inventory) {
        LocalDateTime localDateTime = LocalDateTime.now();
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        Date date = Date.from(instant);
        inventory.setUpdateTime(date);
        inventoryMapper.updateByPrimaryKey(inventory);
    }

    @Override
    public Inventory findinventorybygoodsidandstoryid(Inventory inventor) {
        Inventory inventory = inventoryMapper.selectBygoodidandstoryid(inventor.getStoreId(),inventor.getGoodsId());
        return inventory;
    }

    @Override
    public Inventory findinventory(Integer goodsId, Integer storeId,String goodsName) {
        Inventory inventory = inventoryMapper.selectByGoodIdAndStoryIdAndCategory(storeId,goodsId,goodsName);
        return inventory;
    }

}
